home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Eagles Nest BBS 1
/
Eagles_Nest_Mac_Collection_Disc_1.TOAST
/
Special Hardware
/
CoStar202#2
/
CoStar Disk 2
/
For Programmers Only
/
CoStar Driver API
/
CoStarAPI.c
next >
Wrap
C/C++ Source or Header
|
1993-04-26
|
14KB
|
589 lines
#include <Devices.h>
//#include "csCodes.h"
enum {
csPrintGraphic = 0x82,
csGetStatus,
csGetPrinterList,
csChoosePrinter,
csGetCommandList,
csSendPrinterCommand,
csStyleDialog,
csJobDialog,
csGetPageSizeList,
csGetPrintRecord,
csOpenDoc,
csCloseDoc,
csSetResolution,
csGetSuppList,
csPrValidate,
csStoreTemplate,
csSuspendPrinting,
csResumePrinting,
csCancelPrinting,
csGetIcon,
csDeleteTemplate,
csChooseTemplates,
csSetProcPtrs
};
#include "CoStarAPI.h"
#define rDriverName ".CoStarDriver"
/**************** Globals *****************************************/
short gDrvrRefNum;
/**************** Declarations ************************************/
void ClrCntrlParam(CntrlParam *ctlParamP);
/**************** Functions ***************************************/
/*
* This call returns the refNum of the CoStar driver.
* It also places this refNum in the global variable gDrvrRefNum.
* This global is used by the rest of the calls, so InitCoStarDriver
* MUST be called before any of the other API calls.
*/
short InitCoStarDriver()
{
OSErr err;
err = OpenDriver("\p.CoStarDriver", &gDrvrRefNum);
if(err) return(0);
else return(gDrvrRefNum);
}
/*
* Returns a handle to the list of printers supported by the INIT.
*/
SuppPrListHandle GetSuppPrinterList()
{
CntrlParam ctlParam;
SuppPrListHandle prListH;
ClrCntrlParam(&ctlParam);
ctlParam.ioCRefNum = gDrvrRefNum;
ctlParam.csCode = csGetSuppList;
PBControl((ParmBlkPtr ) &ctlParam, false);
prListH = *((SuppPrListHandle *) &(ctlParam.csParam[0]));
return(prListH);
}
/*
* Returns a handle to the printer list of the type indicated.
* It will run a dialog to edit the list if opCode has bit 0 set.
* It will only include network printers if opCode has bit 1 set.
*/
PrListHndl GetPrinterList(PrinterID prID, char opCode)
{
CntrlParam ctlParam;
PrListHndl prListH;
ClrCntrlParam(&ctlParam);
ctlParam.ioCRefNum = gDrvrRefNum;
ctlParam.csCode = csGetPrinterList;
*((PrinterID *) &(ctlParam.csParam[0])) = prID;
*((char *) &(ctlParam.csParam[1])) = opCode;
PBControl((ParmBlkPtr ) &ctlParam, false);
prListH = *((PrListHndl *) &(ctlParam.csParam[2]));
return(prListH);
}
/*
* This call is used to indicate which printer will be used for subsequent calls.
* It will run a dialog to choose the printer if opCode has bit 0 set.
* It will only include network printers if opCode has bit 1 set.
*/
PrinterID ChoosePrinter(PrinterID prID, char opCode)
{
CntrlParam ctlParam;
ClrCntrlParam(&ctlParam);
ctlParam.ioCRefNum = gDrvrRefNum;
ctlParam.csCode = csChoosePrinter;
*((PrinterID *) &(ctlParam.csParam[0])) = prID;
*((char *) &(ctlParam.csParam[1])) = opCode;
PBControl((ParmBlkPtr ) &ctlParam, false);
prID = *((PrinterID *) &(ctlParam.csParam[2]));
return(prID);
}
/*
* Gets a default print handle for the indicated printer type.
*/
THPrint GetPrintRec(PrinterID printID)
{
THPrint printH;
CntrlParam ctlParam;
ClrCntrlParam(&ctlParam);
ctlParam.ioCRefNum = gDrvrRefNum;
ctlParam.csCode = csGetPrintRecord;
ctlParam.csParam[0] = printID;
PBControl((ParmBlkPtr ) &ctlParam, false);
printH = *((THPrint *) &(ctlParam.csParam[1]));
return(printH);
}
/*
* Runs the style dialog for the passed print record handle.
* If updatePrefs is true, this print handle is stored in the prefs file.
*/
Boolean StlDialog(THPrint printH, Boolean updatePrefs)
{
Boolean result;
CntrlParam ctlParam;
ClrCntrlParam(&ctlParam);
ctlParam.ioCRefNum = gDrvrRefNum;
ctlParam.csCode = csStyleDialog;
*((THPrint *) &(ctlParam.csParam[0])) = printH;
*((Boolean *) &(ctlParam.csParam[2])) = updatePrefs;
PBControl((ParmBlkPtr ) &ctlParam, false);
result = ctlParam.csParam[3];
return(result);
}
/*
* Runs the job dialog for the passed print record handle.
*/
Boolean JobDialog(THPrint printH)
{
Boolean result;
CntrlParam ctlParam;
ClrCntrlParam(&ctlParam);
ctlParam.ioCRefNum = gDrvrRefNum;
ctlParam.csCode = csJobDialog;
*((THPrint *) &(ctlParam.csParam[0])) = printH;
PBControl((ParmBlkPtr ) &ctlParam, false);
result = ctlParam.csParam[2];
return(result);
}
/*
* Validates the passed PREC to insure it's OK for prID.
*/
Boolean ValidatePrintRec(THPrint printH, PrinterID prID)
{
Boolean result;
CntrlParam ctlParam;
ClrCntrlParam(&ctlParam);
ctlParam.ioCRefNum = gDrvrRefNum;
ctlParam.csCode = csPrValidate;
*((THPrint *) &(ctlParam.csParam[0])) = printH;
ctlParam.csParam[2] = prID;
PBControl((ParmBlkPtr ) &ctlParam, false);
result = ctlParam.csParam[3];
return(result);
}
/*
* Opens a document for spooling pictures.
*/
OSErr OpenDoc(THPrint printH)
{
OSErr result;
long jobID;
CntrlParam ctlParam;
ClrCntrlParam(&ctlParam);
ctlParam.ioCRefNum = gDrvrRefNum;
ctlParam.csCode = csOpenDoc;
*((THPrint *) &(ctlParam.csParam[0])) = printH;
PBControl((ParmBlkPtr ) &ctlParam, false);
result = ctlParam.csParam[2];
jobID = *((long *) &(ctlParam.csParam[3]));
return(result);
}
/*
* Closes the spooled document.
*/
OSErr CloseDoc(THPrint printH)
{
OSErr result;
CntrlParam ctlParam;
ClrCntrlParam(&ctlParam);
ctlParam.ioCRefNum = gDrvrRefNum;
ctlParam.csCode = csCloseDoc;
*((THPrint *) &(ctlParam.csParam[0])) = printH;
PBControl((ParmBlkPtr ) &ctlParam, false);
result = ctlParam.csParam[2];
return(result);
}
OSErr SuspendPrinting()
{
OSErr result;
CntrlParam ctlParam;
ClrCntrlParam(&ctlParam);
ctlParam.ioCRefNum = gDrvrRefNum;
ctlParam.csCode = csSuspendPrinting;
PBControl((ParmBlkPtr ) &ctlParam, false);
result = ctlParam.csParam[0];
return(result);
}
OSErr ResumePrinting()
{
OSErr result;
CntrlParam ctlParam;
ClrCntrlParam(&ctlParam);
ctlParam.ioCRefNum = gDrvrRefNum;
ctlParam.csCode = csResumePrinting;
PBControl((ParmBlkPtr ) &ctlParam, false);
result = ctlParam.csParam[0];
return(result);
}
OSErr CancelPrinting(long jobID)
{
OSErr result;
CntrlParam ctlParam;
ClrCntrlParam(&ctlParam);
ctlParam.ioCRefNum = gDrvrRefNum;
ctlParam.csCode = csCancelPrinting;
*((long *) &(ctlParam.csParam[0])) = jobID;
PBControl((ParmBlkPtr ) &ctlParam, false);
result = ctlParam.csParam[2];
return(result);
}
/*
*/
Handle GetPrinterIcon(PrinterID prID, short screenDepth)
{
Handle result;
CntrlParam ctlParam;
ClrCntrlParam(&ctlParam);
ctlParam.ioCRefNum = gDrvrRefNum;
ctlParam.csCode = csGetIcon;
ctlParam.csParam[0] = prID;
ctlParam.csParam[1] = screenDepth;
PBControl((ParmBlkPtr ) &ctlParam, false);
result = *((Handle *) &(ctlParam.csParam[2]));
return(result);
}
/*
*/
OSErr StoreTemplate(PicHandle picH, THPrint printH, Ptr nameP, MailAddrPtr mailAddrP)
{
OSErr result;
CntrlParam ctlParam;
ClrCntrlParam(&ctlParam);
ctlParam.ioCRefNum = gDrvrRefNum;
ctlParam.csCode = csStoreTemplate;
*((PicHandle *) &(ctlParam.csParam[0])) = picH;
*((THPrint *) &(ctlParam.csParam[2])) = printH;
*((Ptr *) &(ctlParam.csParam[4])) = nameP;
*((MailAddrPtr *) &(ctlParam.csParam[6])) = mailAddrP;
PBControl((ParmBlkPtr ) &ctlParam, false);
result = ctlParam.csParam[8];
return(result);
}
OSErr DeleteTemplate(Ptr nameP, PrinterID printID)
{
OSErr result;
CntrlParam ctlParam;
ClrCntrlParam(&ctlParam);
ctlParam.ioCRefNum = gDrvrRefNum;
ctlParam.csCode = csDeleteTemplate;
*((Ptr *) &(ctlParam.csParam[0])) = nameP;
*((PrinterID *) &(ctlParam.csParam[2])) = printID;
PBControl((ParmBlkPtr ) &ctlParam, false);
result = ctlParam.csParam[3];
return(result);
}
OSErr ChooseTemplate(Ptr nameP, PrinterID printID)
{
OSErr result;
CntrlParam ctlParam;
ClrCntrlParam(&ctlParam);
ctlParam.ioCRefNum = gDrvrRefNum;
ctlParam.csCode = csChooseTemplates;
*((Ptr *) &(ctlParam.csParam[0])) = nameP;
*((PrinterID *) &(ctlParam.csParam[2])) = printID;
PBControl((ParmBlkPtr ) &ctlParam, false);
result = ctlParam.csParam[3];
return(result);
}
/*
* Spools a label (or labels) for the passed print record handle.
* Uses the passed PicHandle for the image to be printed.
*/
OSErr PrintGraphic(PicHandle picH, THPrint printH, Ptr tmplNameP, RectListPtr nRectP)
{
OSErr result;
CntrlParam ctlParam;
ClrCntrlParam(&ctlParam);
ctlParam.ioCRefNum = gDrvrRefNum;
ctlParam.csCode = csPrintGraphic;
*((PicHandle *) &(ctlParam.csParam[0])) = picH;
*((THPrint *) &(ctlParam.csParam[2])) = printH;
*((Ptr *) &(ctlParam.csParam[4])) = tmplNameP;
*((RectListPtr *) &(ctlParam.csParam[6])) = nRectP;
PBControl((ParmBlkPtr ) &ctlParam, false);
result = ctlParam.csParam[8];
return(result);
}
/*
* Returns the command list for the indicated printer type.
*/
PrCmdListHndl GetPrinterCommands(PrinterID prID)
{
CntrlParam ctlParam;
PrCmdListHndl prCmdListH;
ClrCntrlParam(&ctlParam);
ctlParam.ioCRefNum = gDrvrRefNum;
ctlParam.csCode = csGetCommandList;
*((PrinterID *) &(ctlParam.csParam[0])) = prID;
PBControl((ParmBlkPtr ) &ctlParam, false);
prCmdListH = *((PrCmdListHndl *) &(ctlParam.csParam[1]));
return(prCmdListH);
}
/*
* Sends the passed command to the printer.
*/
OSErr SendPrinterCommand(CommandID theCommand, PrinterID prID)
{
OSErr err;
CntrlParam ctlParam;
ClrCntrlParam(&ctlParam);
ctlParam.ioCRefNum = gDrvrRefNum;
ctlParam.csCode = csSendPrinterCommand;
*((CommandID *) (ctlParam.csParam)) = theCommand;
*((PrinterID *) (&ctlParam.csParam[1])) = prID;
PBControl((ParmBlkPtr ) &ctlParam, false);
err = ctlParam.csParam[2];
return(err);
}
/*
* Sets resolution of the printH.
*/
void SetResolution(THPrint printH, Boolean setHigh)
{
CntrlParam ctlParam;
ClrCntrlParam(&ctlParam);
ctlParam.ioCRefNum = gDrvrRefNum;
ctlParam.csCode = csSetResolution;
*((THPrint *) &(ctlParam.csParam[0])) = printH;
*((Boolean *) &(ctlParam.csParam[2])) = setHigh;
PBControl((ParmBlkPtr ) &ctlParam, false);
}
/*
* Returns the page size list for the indicated printer type.
*/
PgInfoListHndl GetPageSizes(PrinterID prID)
{
CntrlParam ctlParam;
PgInfoListHndl pgSizeListH;
ClrCntrlParam(&ctlParam);
ctlParam.ioCRefNum = gDrvrRefNum;
ctlParam.csCode = csGetPageSizeList;
*((PrinterID *) (ctlParam.csParam)) = prID;
PBControl((ParmBlkPtr ) &ctlParam, false);
pgSizeListH = *((PgInfoListHndl *) &(ctlParam.csParam[1]));
return(pgSizeListH);
}
/*
* Utility routine for clearing a CntrlParam block.
*/
void ClrCntrlParam(CntrlParam *ctlParamP)
{
Ptr charP = (Ptr ) ctlParamP;
short length = sizeof(CntrlParam);
while (length--)
(*charP++) = 0;
}
#if 0
Here are some code fragments as examples of how to use these calls:
/*
* Print a graphic onto a printer chosen by the user.
* picH is some picture you'd like to see on a label.
*/
PrintAGraphic(PicHandle picH)
{
THPrint printH; /* A print record handle */
PrinterID prID; /* The ID of the printer chosen for this label. */
InitCoStarDriver(); /* Get the driver's ID */
prID = ChoosePrinter(0, true); /* Choose a printer */
printH = GetPrintRec(prID); /* Get the default print record. */
if(StlDialog(printH, true)){ /* Run the style dialog. */
if(JobDialog(printH)){ /* Run the job dialog. */
PrintGraphic(picH, printH); /* Print the graphic. */
}
}
}
/*
* Build a menu from the printer list,
* and allow the user to choose a printer from that menu.
*/
ChoosePrinterMenu(MenuHandle menuH)
{
PrListHndl prListH;
PrinterSpecPtr prSpecP;
short i;
InitCoStarDriver(); /* Get the driver's ID */
prListH = GetPrinterList(prID, false);
HLock((Handle ) prListH);
prSpecP = (*prListH)->PLList;
/* Fill the menu with the names from the printer list. */
for(i = 0; i < (*prListH)->PLCount; i++, prSpecP++){
InsMenuItem(menuH, "\px", i);
SetItem(menuH, iFirstPrinter + i, prSpecP->PSName);
}
HUnlock((Handle ) prListH);
...When the menu is selected, call the choose printer function...
...itemHit is the menu Item selected...
PrinterSpecPtr prSpecP;
PrinterID prID;
prSpecP = &(*prListH)->PLList[itemHit - 1];
prID = prSpecP->PSID; /* The ID of the selected printer. */
prID = ChoosePrinter(prID, false); /* Choose the printer (without dialog). */
}
/*
* Build a menu of the printer's commands,
* and allow the user to send a command.
*/
PrinterCommandMenu(MenuHandle menuH, PrinterID prID)
{
PrCmdListHndl cmdListH;
PrCmdPtr cmdP;
short i;
InitCoStarDriver(); /* Get the driver's ID */
cmdListH = GetPrinterCommands(prID); /* Pass 0 to use default printer. */
/* Add the names of the commands to the menu. */
HLock((Handle ) cmdListH);
cmdP = (*cmdListH)->PCList;
for(i = 1; i <= (*cmdListH)->PCCount; i++, cmdP++){
InsMenuItem(menuH, "\px", i);
SetItem(menuH, i, cmdP->PCName);
}
HUnlock((Handle ) cmdListH);
...When the menu is selected, call the send command function...
...itemHit is the menu Item selected...
cmdP = &(*cmdListH)->PCList[itemHit - 1];
SendPrinterCommand(cmdP->PCID, prID); /* Send the command to the printer. */
}
/*
*
*/
PrinterTypesMenu()
{
short i;
SuppPrListHandle suppPrH;
SuppPrRecPtr suppPrP;
PrinterID newPrID;
suppPrH = GetSuppPrinterList();
if(suppPrH == nil) return;
HLock((Handle ) suppPrH);
suppPrP = (*suppPrH)->SPLList;
for(i = 0; i < (*suppPrH)->SPLCount; i++, suppPrP++){
InsMenuItem(gTypesMenuH, suppPrP->SPName, 0x7F);
}
DisposeHandle((Handle ) suppPrH);
...When the menu is selected, change the selected printer type...
...itemHit is the menu Item selected...
...gSelPrinterID is a global for the current PrinterID...
suppPrH = GetSuppPrinterList(); /* Get the list of supported printers. */
if(suppPrH == nil) return;
HLock((Handle ) suppPrH);
suppPrP = &(*suppPrH)->SPLList[itemHit - 1];
if(PRTYPE(gSelPrinterID) != PRTYPE(suppPrP->SPDefaultID)){
newPrID = ChoosePrinter(suppPrP->SPDefaultID, false);
gSelPrinterID = newPrID; /* Save the new PrinterID. */
CallGetPrinterList(newPrID, false); /* Get the new printer list. */
...Rebuild the printer list menu...
GetPrinterCommands(newPrID); /* Get the new command list. */
...Rebuild the printer commands menu...
GetPageSizes(newPrID); /* Get the new page size list . */
...Rebuild the page sizes menu...
}
DisposeHandle((Handle ) suppPrH);
}
#endif